package com.star.spring.reactor.flux;


import reactor.core.publisher.Flux;

/**
 * @description: flux拼接demo
 * @author: star
 * @create: 2025-03-05 10:41
 **/

public class FluxConcatDemo {

    public static void main(String[] args) {

//        concat();
//        concatWith();
        concatMap();
        concatMap();
    }


    //    1 concat
    public static void concat() {
        Flux.concat(Flux.just(1, 2, 3), Flux.just("ha", "he", "heng"))
                .log()
                .subscribe();
    }

    //    2 concatWith
    public static void concatWith() {
        Flux.just(1, 2, 3)
                .concatWith(Flux.just(4, 5, 6))
                .log()
                .subscribe();
    }

    //    3 concatMap
    public static void concatMap() {
        Flux.just(1, 2, 3)
                .concatMap(i -> Flux.just(i, i + 1))
                .log()
                .subscribe();
    }

    //    4 concatMap
    public static void map() {
        Flux.just(1, 2, 3)
                .map(i -> i + 1)
                .log()
                .subscribe();
    }
}
